//using System;
//using System.Collections.Generic;
//using System.Text;

using System;
namespace GeneticAlgorithm.CP3
{
    class Fitness
    {


        public static float A(float[] output)
        {
            // DEBUG stub fitness function, let's try to genetically evolve the function x^2 + 6x + 11

            // compare current function output with optimal output
            float error = 0;
            for (int i = 0; i < output.Length; i++)
            {
                float actual = i * i * i + i * i + 6f * i + 11f;
                error += Math.Abs(actual - output[i]);
            }

            // get error average
            error /= output.Length;

            // HACK adaptive cutff
            if (error > 40000f)
            {
                return 0;
            }
            else
            {
                return 1f - error / 40000f;
            }
        }
    }
}
